package com.hxci.pointmap.dao;

import com.hxci.pointmap.utils.DBUtils;

import java.util.List;
import java.util.Map;

public class DevDAO {

    DBUtils dbUtils = new DBUtils();
    public int insertDev(List paramList) {
        String sql = "INSERT INTO device_info (" +
                "dev_name, dev_type, lon, " +
                "lat, is_valid,icon_name) " +
                "VALUES " +
                "(" +
                "?, ?, ?," +
                "?, ?, ?" +
                ")";
            int result = dbUtils.doUpdate(sql, paramList);
            return  result;
    }

    public List<Map<String, Object>> queryDevList(String sql, List paramList) {
        List<Map<String, Object>> resultList =dbUtils.doQuery(sql, paramList);
        return resultList;
    }

    public List<Map<String, Object>> queryDevById(List paramList) {

        String sql = " SELECT " +
                " t.dev_id, " +
                " t.dev_name, " +
                " t.dev_type, " +
                " t.lat, " +
                " t.lon, " +
                " ifnull(t.is_valid,'')is_valid ," +
                " ifnull(t.icon_name,'')icon_name " +
                "FROM " +
                " device_info t " +
                "WHERE " +
                " t.dev_id = ? " ;
        List<Map<String, Object>> mapList =dbUtils.doQuery(sql, paramList);
        return mapList;
    }
    public int updateDev(List paramList) {
        String sql = "UPDATE device_info " +
                "SET dev_name = ?, " +
                " dev_type = ?," +
                " lon = ?," +
                " lat = ?, " +
                " is_valid = ?," +
                " icon_name = ?" +
                " WHERE dev_id = ?";
        return dbUtils.doUpdate(sql, paramList);
    }


    public List<Map<String, Object>> queryAllDev(List paramList) {

        String sql = " SELECT " +
                " t.dev_id, " +
                " t.dev_name, " +
                " t.dev_type, " +
                " t.lat, " +
                " t.lon, " +
                " ifnull(t.is_valid,'')is_valid ," +
                " ifnull(t.icon_name,'')icon_name " +
                "FROM " +
                " device_info t " ;
        List<Map<String, Object>> mapList =dbUtils.doQuery(sql, paramList);
        return mapList;
    }

    public int deleteDev(List paramList) {
        String sql = "DELETE FROM device_info WHERE dev_id = ?";
        int result = dbUtils.doUpdate(sql, paramList);
        return result;
    }
}
